#include <iostream>

#include "game.h"

using namespace std;

int main(int argc, char const *argv[])
{
    char gobang_ui[ROW][COL];
    char pawn = ' ';
    int flag = 1;
    int row = 0;
    int col = 0;

    gobang_ui_init(gobang_ui);

    while (1)
    {
        show_gobong_ui(gobang_ui);
        if (flag % 2 == 1)
        {
            pawn = 'B';

            cout << "请黑棋落子，请输入落在下标位置：例如 1 2 : " << endl;
            cin >> row >> col;

            if (play_chess(gobang_ui, row, col, pawn) == -1)
            {
                cout << pawn << "方输入错误下标位置，请重新输入" << endl;
            }
            else
            {
                flag++;
            }
        }
        else
        {
            pawn = 'W';

            cout << "请白棋落子，请输入落在下标位置：例如 1 2 : " << endl;
            cin >> row >> col;

            if (play_chess(gobang_ui, row, col, pawn) == -1)
            {
                cout << pawn << "方输出错误下标位置，请重新输入" << endl;
            }
            else
            {
                flag++;
            }
        }

        // 判断是否胜利
        if (check_victory(gobang_ui, row, col, pawn))
        {
            cout << "GOD JOB!!!恭喜" << pawn << "方，获得胜利" << endl;

            show_gobong_ui(gobang_ui);

            break;
        }
    }

    return 0;
}
